home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_31791.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  33 lines

  1. -- card: 31791 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. POINTER ARGUMENTS
  11.  
  12. Since a function cannot alter the value of a variable which is passed as an argument, it may appear that the only way for a function to communicate with its calling function is via the return value.  Another way of establishing communication between functions is through global variables (variables with file scope).  However, the use of global variables can cause code to be difficult to debug and maintain.
  13.  
  14. A technique commonly used in C programs is to declare a formal parameter of the function to be a pointer variable*.  The calling program passes the address of a variable (using the '&' operator) as an argument to the function.  The called function may assign a new value to the variable "pointed to" by its pointer parameter, thus altering the value of a variable in the calling function.
  15.  
  16. In effect, the block scope of the calling function's variable is subverted by making the variable accessible from within another function's body.  However, this is considered less problematic than the use of global variables since the scope boundaries remain well-defined.
  17.  
  18.  
  19. -- part contents for background part 7
  20. ----- text -----
  21. 89
  22.  
  23. -- part contents for background part 29
  24. ----- text -----
  25. 20555
  26.  
  27. -- part contents for background part 27
  28. ----- text -----
  29. Pointer variables
  30.  
  31. -- part contents for background part 20
  32. ----- text -----
  33. Pointer variables - p57